package com.bms.controller;

import com.bms.Dao.BookDao;
import com.bms.bean.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class BookController {

    @Autowired
    BookDao bookDao;

    //    新书上架
    @RequestMapping("/onBook")
    public void onBook(@RequestBody Book book) {
        System.out.println("图书入库前端："+book);
        int number = book.getBookleft();
        Book[] books = bookDao.getBookByNumber(book.getBooknumber());
        if (books != null && books.length > 0)
            bookDao.addBook(books[0].getBookid(), number);
        else
            bookDao.onBook(book.getBookname(), book.getBookauthor(), book.getBookname(), number, book.getBooklocation(), book.getBookontime());
    }

    //    下架
    @RequestMapping("/outBook")
    public void outBook(@RequestBody Book book) {
        bookDao.outBook(book.getBookname());
    }
}
